package com.caiyigo.baihua.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.stereotype.Repository;

import com.caiyigo.baihua.dto.LogDto;
import com.caiyigo.baihua.model.SystemLog;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;

/**
 * @author caihaihui
 *
 */
@Repository
public class SystemLogMapperSql implements SystemLogMapper {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.dao.SystemLogMapper#deleteByPrimaryKey(java.lang.Integer)
	 */
	@Override
	public int deleteByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.dao.SystemLogMapper#insert(com.caiyigo.zoo.model.SystemLog
	 * )
	 */
	@Override
	public int insert(SystemLog record) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.dao.SystemLogMapper#insertSelective(com.caiyigo.zoo.model
	 * .SystemLog)
	 */
	@Override
	public int insertSelective(SystemLog record) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.dao.SystemLogMapper#selectByPrimaryKey(java.lang.Integer)
	 */
	@Override
	public SystemLog selectByPrimaryKey(Integer id) {
		// TODO Auto-generated method stub
		return null;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.dao.SystemLogMapper#updateByPrimaryKeySelective(com.caiyigo
	 * .zoo.model.SystemLog)
	 */
	@Override
	public int updateByPrimaryKeySelective(SystemLog record) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.dao.SystemLogMapper#updateByPrimaryKey(com.caiyigo.zoo
	 * .model.SystemLog)
	 */
	@Override
	public int updateByPrimaryKey(SystemLog record) {
		// TODO Auto-generated method stub
		return 0;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.caiyigo.zoo.dao.SystemLogMapper#list(com.github.miemiedev.mybatis
	 * .paginator.domain.PageBounds)
	 */
	@Override
	public List list(LogDto log, PageBounds pageBounds) {
		Map<String, Object> params = new HashMap<String, Object>();
		if (StringUtils.isNotEmpty(log.getDateEnd())) {
			params.put(LogDto.FileConstant.DATEEND, log.getDateEnd());
		}
		if (StringUtils.isNotEmpty(log.getDateStart())) {
			params.put(LogDto.FileConstant.DATESTART, log.getDateStart());
		}
		if (null != log.getOperation()) {
			params.put(LogDto.FileConstant.OPERATION, log.getOperation());
		}
		List<Object> list = null;
		SqlSession session = sqlSessionFactory.openSession();
		try {
			list = session.selectList(
					"com.caiyigo.baihua.dao.SystemLogMapper.list", params,
					pageBounds);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			session.close();
		}

		return list;
	}

	private SqlSessionFactory sqlSessionFactory;

	public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) {
		this.sqlSessionFactory = sqlSessionFactory;
	}
}
